// pages/index/index.js
const api = require('../../API/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    banner: [], //轮播数组
    newSong: [], //最新歌曲
    newSong_slice: [], //截取6个
    station_slice: [], //电台截取
    albumsList_slice: [], //最新专辑截取,
    perferedList:[], //今日优选

    workList_slice: [],  //创作截取
    workList: [], //创作完整
    electron_slice: [], //3D电子截取
    electron: [],  //3D电子完整
    LourList:[],  //电台节目榜完整
    LourList_slice:[], //电台节目榜截取
    AnchorList:[], //电台24小时主播榜
    AnchorList_slice:[],//电台24小时主播榜截取
    Newcomer:[], //电台主播新人榜
    Newcomer_slice:[],//电台主播新人榜截取
    popularList:[], //电台最热主播榜
    popularList_slice:[], //电台最热主播榜截取
  },
  switchNav(e) {
    console.log(e.target.dataset.current);
    if (this.data.currentTab == e.target.dataset.current) {
      return false;
    } else {
      this.setData({
        currentTab: e.target.dataset.current
      })
    }
  },

  switchTab(e) {
    // console.log(e.detail.current);
    this.setData({
      currentTab: e.detail.current
    })
  },
  getBanner() {
    api.getBanner({
      type: 2
    }).then((res) => {
      if (res.code === 200) {
        console.log('banner:',res.banners);
        this.setData({
          banner: res.banners
        })
      }
    })
  },
  getNewSong() {
    api.getNewSong({}).then((res) => {
      if (res.code === 200) {
        this.setData({
          newSong: res.result,
          newSong_slice: res.result.slice(0, 6)
        })

      }
    })
  },
  getStaion() {
    api.getStation({}).then(res => {
      this.setData({
        station_slice: res.djRadios.slice(0, 6)
      })

    })
  },
  getNewAlbum() {
    api.getNewAlbum({}).then(res => {
      if (res.code === 200) {

        this.setData({
          albumsList_slice: res.albums.slice(6, 12)
        })

      }
    })
  },

  getHotStation() {
    api.getHotStation({
      cateId: 2001
    }).then(res => {
      if (res.code == 200) {
        this.setData({
          workList_slice: res.djRadios.slice(4, 7),
          workList: res.djRadios
        })
      }

    })

    api.getHotStation({
      cateId: 10002
    }).then(res => {
      if (res.code == 200) {
        this.setData({
          electron_slice: res.djRadios.slice(0, 3),
          electron: res.djRadios
        })
      }
    })
  },

  getLourList(){
      api.getLourList({limit:30}).then(res=>{
       if(res.code === 200){
          // console.log(res.data.list);
          this.setData({
            LourList:res.data.list,
            LourList_slice:res.data.list.slice(3,6)
          })
       }
      })
  },

  getAnchorList(){
    api.getAnchorList({limit:30}).then(res=>{
      if(res.code === 200){
        //  console.log(res.data.list);
         this.setData({
           AnchorList:res.data.list,
           AnchorList_slice:res.data.list.slice(4,7)
         })
      }
     })
  },

  getNewcomer(){
    api.getNewcomer({limit:30}).then(res=>{
      if(res.code === 200){
        this.setData({
          Newcomer:res.data.list,
          Newcomer_slice:res.data.list.slice(14,17)
        })
     }
    })
  },

  getPopularList(){
    api.getPopularList({limit:30}).then(res=>{
      if(res.code === 200){
        this.setData({
          popularList:res.data.list,
          popularList_slice:res.data.list.slice(0,6)
        })
     }
    })
  },
  getTodayPerfered(){
      api.getTodayPerfered({}).then(res =>{
        if(res.code === 200){
          console.log(res.data);
          this.setData({
            perferedList:res.data
          })
       }
      })
  },

  // 换一换更改内容
  // 更改创新内容
  changeContent1(){
      const length =  this.data.workList.length;
      let content1 = parseInt(Math.random() * length);
      let content2 = parseInt(Math.random() * length);
      let content3 = parseInt(Math.random() * length);
      let newList = [];
      newList.unshift(this.data.workList[content1]);
      newList.unshift(this.data.workList[content2]);
      newList.unshift(this.data.workList[content3]);
      console.log(newList);
      this.setData({
        workList_slice:newList
      })
  },
  // 更改3D电子内容
  changeContent2(){
    const length =  this.data.electron.length;
    let content1 = parseInt(Math.random() * length);
    let content2 = parseInt(Math.random() * length);
    let content3 = parseInt(Math.random() * length);
    let newList = [];
    newList.unshift(this.data.electron[content1]);
    newList.unshift(this.data.electron[content2]);
    newList.unshift(this.data.electron[content3]);
    console.log(newList);
    this.setData({
      electron_slice:newList
    })
  },

    // 电台节目榜
  changeContent3(){
    const length =  this.data.LourList.length;
    let content1 = parseInt(Math.random() * length);
    let content2 = parseInt(Math.random() * length);
    let content3 = parseInt(Math.random() * length);
    let newList = [];
    newList.unshift(this.data.LourList[content1]);
    newList.unshift(this.data.LourList[content2]);
    newList.unshift(this.data.LourList[content3]);
    console.log(newList);
    this.setData({
      LourList_slice:newList
    })
  },

  // 电台主播榜
  changeContent4(){
    const length =  this.data.AnchorList.length;
    let content1 = parseInt(Math.random() * length);
    let content2 = parseInt(Math.random() * length);
    let content3 = parseInt(Math.random() * length);
    let newList = [];
    newList.unshift(this.data.AnchorList[content1]);
    newList.unshift(this.data.AnchorList[content2]);
    newList.unshift(this.data.AnchorList[content3]);
    console.log(newList);
    this.setData({
      AnchorList_slice:newList
    })
  },
  // 电台新人榜
  changeContent5(){
    const length =  this.data.Newcomer.length;
    let content1 = parseInt(Math.random() * length);
    let content2 = parseInt(Math.random() * length);
    let content3 = parseInt(Math.random() * length);
    let newList = [];
    newList.unshift(this.data.Newcomer[content1]);
    newList.unshift(this.data.Newcomer[content2]);
    newList.unshift(this.data.Newcomer[content3]);
    console.log(newList);
    this.setData({
      Newcomer_slice:newList
    })
  },

  PlayAudio(e) {
    console.log(e);
    const audioId = e.currentTarget.dataset.id
    console.log(audioId);
   wx.navigateTo({
     url: '../playAudio/playAudio?id='+ audioId, 
   })
  },

  playRadio(){
    wx.showModal({
      cancelColor: '#19CAAD',
      cancelText: '取消',
      confirmColor: '#19CAAD',
      confirmText: '确定',
      content: '敬请期待',
      showCancel: true,
      title: '电台功能正在努力',
      success: (result) => {
      },
     
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBanner(); //获取个人推荐轮播
    this.getNewSong(); //获取最新歌曲
    this.getStaion(); //获取精选电台
    this.getNewAlbum(); //获取最新专辑
    this.getHotStation(); //获得电台热，创作，3D电子
    this.getLourList();  //获取电台节目榜
    this.getAnchorList(); //获取24小时主播榜
    this.getNewcomer(); //获取主播新人榜
    this.getPopularList(); //获取最热主播榜
    this.getTodayPerfered(); //获取今日优选
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})